﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Sinacor.OMM.HealthMonitor.Entity.HftProcessor;

namespace Sinacor.OMM.HealthMonitor.Collector.SharedHealthDataMemoryStorage.HftProcessor
{
    [Serializable]
    public class HftProcessorShdms : IDisposable
    {
        private static HftProcessorShdms _hftProcessorShmds;
        private static Mutex mtx = new Mutex();

        private HftProcessorShdms()
        {

        }

        public static HftProcessorShdms GetSharedStorage()
        {
            mtx.WaitOne();
            if (_hftProcessorShmds == null)
            {
                _hftProcessorShmds = new HftProcessorShdms();
            }
            mtx.ReleaseMutex();

            return _hftProcessorShmds;
        }

        public string HftProcessId
        {
            get 
            { 
                return _hftProcessorData.HftId; 
            }
        }


        private HftProcessorData _hftProcessorData;
        public HftProcessorData HFTProcessorDataInfo
        {
            get
            {
                if (_hftProcessorData == null)
                    _hftProcessorData = new HftProcessorData();

                return _hftProcessorData;
            }
        }

        #region IDisposable Members

        public void Dispose()
        {
            _hftProcessorShmds = null;
            mtx.Close();
            _hftProcessorData = null;
        }

        #endregion
    }
}
